<?php

/**
 * 首页
 * david.yan (david.yan@qq.com) by 2013
 * 北京泰和盈动科技有公司 版权所有
 */
class log extends actionAbstract {

    public $title = '';
    public $css = array();
    public $modules = array();
    public $menu = array();
    public $pos = 3;
    public $type = 0;
    public $leftpos = 0;

    /**
     * 递归要添加的菜单PIN
     *
     * @var array
     */
    protected $add_auth = array();

    /**
     * 构造
     */
    function __construct() {
        parent::__construct();
        $this->info = acl::checkLogin('admininfo', $this->url('common/login'));
        //     if(!isset($_SESSION['admininfo'])){ header('location:'.$this->url('common/login'));}
        $this->menu = $this->loadConfig();
        $this->type = isset($_GET['type']) ? (int) $_GET['type'] : 0;
    }

    //api日志
    public function apiLog() {
        $this->leftpos = 0;
        $this->loadModel('apiosii', 'log');
        $re = $this->apiosii->logModel->fetchAll("SELECT * FROM apiosii_log ORDER BY created DESC");

        include $this->loadWidget('masterTheme');
    }

    //订单日志
    public function orderLog() {
        $this->leftpos = 1;
        $this->loadModel('orders', 'log');
		
		$page=isset($_GET['page'])?(int)($_GET['page']):1;
		$nameKey=isset($_GET['nameKey'])?$_GET['nameKey']:'';
		
		$sql_from=" from orders_log";
		$sql_where=" where id>0";
		$sql_order_by=" order by id desc";
		$field_reto=" count(id)";
		$field_re=" *";
		
		if(trim($nameKey,',')){
			$keyArr=explode(',',$nameKey);
			foreach($keyArr as $k=>$v){
				$sql_where.=" and (operationName like '%".trim($v)."%' or operationType like '%".trim($v)."%'";
				$sql_where.=" or hotelName like '%".trim($v)."%' or orderNum like '%".trim($v)."%' or created like '%".trim($v)."%')";
			}
		}
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"message","log",$page);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];$size=$return['size'];
		
        include $this->loadWidget('masterTheme');
    }

    //酒店日志
    public function hotelLog() {
        $this->leftpos = 2;

        $this->loadModel('hotel', 'log');
        $this->loadModel('hotel', 'category');
        $this->loadModel('pms', 'account');
        $re = $this->hotel->logModel->fetchAll("SELECT a.*,b.hotelName,c.userName FROM hotel_log AS a "
                . " LEFT JOIN hotel_category AS b ON a.hotelId=b.id left join pms_account as c on a.pmsId=c.id"
                . " ORDER BY created DESC");


        include $this->loadWidget('masterTheme');
    }
    
    //短信日志
    public function messageLog() {
        $this->leftpos = 3;
        $this->loadModel('message', 'log');
		
		$page=isset($_GET['page'])?(int)($_GET['page']):1;
		$nameKey=isset($_GET['nameKey'])?$_GET['nameKey']:'';
		
		$sql_from=" from message_log";
		$sql_where=" where id>0";
		$sql_order_by=" order by id desc";
		$field_reto=" count(id)";
		$field_re=" *";
		
		if(trim($nameKey,',')){
			$keyArr=explode(',',$nameKey);
			$sql_where.=" and (";
			foreach($keyArr as $k=>$v){
				if($k==0){
					$sql_where.=" content like '%".$v."%'";
				}else{
					$sql_where.=" or content like '%".$v."%'";
				}
			}
			$sql_where.=")";
		}
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"message","log",$page);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];$size=$return['size'];
		
        include $this->loadWidget('masterTheme');
    }
	
	function addtypes(){
		$this->loadModel('hotel', 'type');
		$re=$this->hotel->typeModel->fetchAll("select * from hotel_type where zisort=0");
		if($re){
			$addtypes=array();
			$key=0;
			foreach($re as $k=>$v){
				for($i=5;$i<=8;$i++){
					$addtypes[$key]['categoryid']=$v['categoryid'];
					if($i==5){
						$addtypes[$key]['title']=$v['title']."(含早)(现付)";
					}elseif($i==6){
						$addtypes[$key]['title']=$v['title']."(不含早)(现付)";
					}elseif($i==7){
						$addtypes[$key]['title']=$v['title']."(提前1天以上预订)(现付)";
					}elseif($i==8){
						$addtypes[$key]['title']=$v['title']."(连续1天以上入住)(现付)";
					}
					$addtypes[$key]['zisort']=$i;
					$addtypes[$key]['bed']=$v['bed'];
					$addtypes[$key]['maxnumber']=$v['maxnumber'];
					$addtypes[$key]['breakfast']=$v['breakfast'];
					$addtypes[$key]['floor']=$v['floor'];
					$addtypes[$key]['area']=$v['area'];
					$addtypes[$key]['price']=$v['price'];
					$addtypes[$key]['status']=1;
					$addtypes[$key]['parentTypeId']=$v['id'];
					$addtypes[$key]['roomNum']=0;
					$key++;
				}
			}
			foreach($addtypes as $k=>$v){
				$reto=$this->hotel->typeModel->insert($v);
				if(!$reto){unset($addtypes[$k]);}
			}
			echo "<pre>";print_r($addtypes);
		}
	}
}
